package net.mihome.app.ui;

import net.mihome.app.R;
import net.mihome.app.bean.NewsType;
import net.mihome.app.ui.view.MihomeZixunView;
import net.mihome.app.ui.view.MyViewLinster;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MihomeNewsListActivity extends BaseActivity {
	MihomeZixunView mihomeZixunView;
	ProgressBar progressBar;
	Handler handler;
	private View backView;
	public static final int STOP_PROGRESS=1;
	public static final int START_PROGRESS=2;
	TextView titleTextView;
	NewsType newsType;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mihome_news_list_main);
		newsType=(NewsType) getIntent().getSerializableExtra("newsType");
		titleTextView=(TextView) findViewById(R.id.mihome_list_head_title_id);
		if(newsType==null){
			this.finish();
			return ;
		}
		titleTextView.setText(newsType.getType_name());
		handler=new Handler(new Handler.Callback() {
			@Override
			public boolean handleMessage(Message arg0) {
				switch (arg0.what) {
				case STOP_PROGRESS:
					progressBar.setVisibility(View.GONE);
					break;
				case START_PROGRESS:
					progressBar.setVisibility(View.VISIBLE);
					break;
				default:
					break;
				}
				return false;
			}
		});
		progressBar=(ProgressBar) findViewById(R.id.news_list_head_progress);
		mihomeZixunView=(MihomeZixunView) findViewById(R.id.mifuwu_news_listview);
		mihomeZixunView.setMyViewLinster(new MyViewLinster() {
			@Override
			public void onLoadComplete() {
				// TODO Auto-generated method stub
				handler.sendEmptyMessage(STOP_PROGRESS);
			}
			@Override
			public void onBeforeLoad() {
				// TODO Auto-generated method stub
				handler.sendEmptyMessage(START_PROGRESS);
				
			}
		});
		mihomeZixunView.initData(newsType.getId());
		backView=findViewById(R.id.mihome_news_lsit_back);
		backView.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				MihomeNewsListActivity.this.finish();
			}
		});
	}
}
